﻿namespace System.ServiceModel.DomainServices.Client
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public abstract class EntityQuery
    {
        private System.ServiceModel.DomainServices.Client.DomainClient _domainClient;
        private Type _entityType;
        private bool _hasSideEffects;
        private bool _includeTotalCount;
        private bool _isComposable;
        private IDictionary<string, object> _parameters;
        private IQueryable _query;
        private string _queryName;

        internal EntityQuery(EntityQuery baseQuery, IQueryable query)
        {
            if (baseQuery == null)
            {
                throw new ArgumentNullException("baseQuery");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            this._domainClient = baseQuery._domainClient;
            this._queryName = baseQuery._queryName;
            this._entityType = baseQuery._entityType;
            this._parameters = baseQuery._parameters;
            this._hasSideEffects = baseQuery._hasSideEffects;
            this._isComposable = baseQuery._isComposable;
            this._includeTotalCount = baseQuery._includeTotalCount;
            this._query = query;
        }

        internal EntityQuery(System.ServiceModel.DomainServices.Client.DomainClient domainClient, string queryName, Type entityType, IDictionary<string, object> parameters, bool hasSideEffects, bool isComposable)
        {
            if (domainClient == null)
            {
                throw new ArgumentNullException("domainClient");
            }
            if (string.IsNullOrEmpty(queryName))
            {
                throw new ArgumentNullException("queryName");
            }
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            this._domainClient = domainClient;
            this._queryName = queryName;
            this._entityType = entityType;
            this._parameters = parameters;
            this._hasSideEffects = hasSideEffects;
            this._isComposable = isComposable;
        }

        public System.ServiceModel.DomainServices.Client.DomainClient DomainClient
        {
            get
            {
                return this._domainClient;
            }
        }

        public Type EntityType
        {
            get
            {
                return this._entityType;
            }
        }

        public bool HasSideEffects
        {
            get
            {
                return this._hasSideEffects;
            }
        }

        public bool IncludeTotalCount
        {
            get
            {
                return this._includeTotalCount;
            }
            set
            {
                this._includeTotalCount = value;
            }
        }

        public bool IsComposable
        {
            get
            {
                return this._isComposable;
            }
        }

        public IDictionary<string, object> Parameters
        {
            get
            {
                return this._parameters;
            }
        }

        public IQueryable Query
        {
            get
            {
                return this._query;
            }
            protected set
            {
                this._query = value;
            }
        }

        public string QueryName
        {
            get
            {
                return this._queryName;
            }
        }
    }
}

